package com.example.home1023;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    ListView listView;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.list_view);
        List<Fruit> fruitlist = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            Fruit pineapple = new Fruit(R.drawable.ic_launcher_background, "菠萝", "$16.9/KG");
            fruitlist.add(pineapple);
            Fruit magngo = new Fruit(R.drawable.ic_launcher_background, "芒果", "$16.9/KG");
            fruitlist.add(magngo);
            Fruit pomegranate = new Fruit(R.drawable.ic_launcher_background, "石榴", "$16.9/KG");
            fruitlist.add(pomegranate);
            Fruit grape = new Fruit(R.drawable.ic_launcher_background, "葡萄", "$16.9/KG");
            fruitlist.add(grape);
            Fruit orange = new Fruit(R.drawable.ic_launcher_background, "橙子", "$16.9/KG");
            fruitlist.add(orange);
        }
        FruitAdapter adapter = new FruitAdapter(MainActivity.this,R.layout.activity_main,fruitlist);
        listView.setAdapter(adapter);


    }
}